package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
)

/**
 The make built-in function allocates and initializes an object of type
 slice, map, or chan (only). Like new, the first argument is a type, not a
 value. Unlike new, make's return type is the same as the type of its
 argument, not a pointer to it. The specification of the result depends on
 the type:
	Slice: The size specifies the length. The capacity of the slice is
	equal to its length. A second integer argument may be provided to
	specify a different capacity; it must be no smaller than the
	length. For example, make([]int, 0, 10) allocates an underlying array
	of size 10 and returns a slice of length 0 and capacity 10 that is
	backed by this underlying array.
	Map: An empty map is allocated with enough space to hold the
	specified number of elements. The size may be omitted, in which case
	a small starting size is allocated.
	Channel: The channel's buffer is initialized with the specified
	buffer capacity. If zero, or the size is omitted, the channel is
	unbuffered.
*/
func main() {
	counts1 := map[string]int{"a": 1, "b": 2}
	counts1["c"]++
	fmt.Println(counts1)
	// var counts = make[map[string]int, 10)
	// 所以这里counts就相当于一个map集合
	// 相当于new一个对象赋值给counts, 但是与传统的new不同, go中的new 与 make的区别要仔细研究
	counts := make(map[string]int, 10)
	fmt.Println(len(counts))
	// 创建一个输入函数
	input := bufio.NewScanner(os.Stdin)
	// 创建一个循环, 出现多少次++才会+1
	for input.Scan() {
		// 每次从dup从中读取一行内容, 这一行就作为map中的key
		// 对应的值递增1
		// line := input.Text()
		// counts[line] = counts[line] + 1
		text := input.Text()
		counts[text]++
	}
	println(counts)
	log.Print("长度为----->", counts)
	// 长度为你输入的多少行, 利用ctrl + d来控制退出 bufio.NewScanner(os.Stdin)
	fmt.Println("长度为: ", len(counts))
	// 注意忽略input.Err()中可能的错误
	// 这里表示的是line表示的是key, n表示的值
	// 由控制台可以看出, 好像是天生的异步
	// %s表示输出字符串, %d以十进制输出
	for line, n := range counts {
		fmt.Printf("索引为: %s", line)
		fmt.Printf("值为: %d", n)
		fmt.Println("\n")

		if n > 1 {
			fmt.Printf("我要做辨别 %d\t%s\n", n, line)
		}
	}
}
